import { FaissStore } from "@langchain/community/vectorstores/faiss";
import { Document } from "langchain/document";
import { useEmbeddings } from "./utils";

export const genVectorStore = async (splitDocs: Document[], dir: string) => {
  // 向量化编码
  const embeddings = useEmbeddings();
  // 本地存储
  const vectorStore = await FaissStore.fromDocuments(splitDocs, embeddings);
  //   const dir = path.resolve(__dirname, "..", "..", "data", "db", "qiu");
  await vectorStore.save(dir);
};

export const loadFromStore = async (dir: string) => {
  // 向量化编码
  const embeddings = useEmbeddings();
  const vectorStore = await FaissStore.load(dir, embeddings);
  return vectorStore;
};
